package com.smackkitty.haikustudio;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;

public class Main extends Activity implements OnClickListener {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.main);
        
        View btnWriteHaiku = findViewById(R.id.btn_writeHaiku);
        btnWriteHaiku.setOnClickListener(this);
        
        View imgTwitter = findViewById(R.id.img_lnkTwitter);
        imgTwitter.setOnClickListener(this);
        
        View imgFacebook = findViewById(R.id.img_lnkFacebook);
        imgFacebook.setOnClickListener(this);
        
        View imgBlogspot = findViewById(R.id.img_lnkBlogspot);
        imgBlogspot.setOnClickListener(this);
    }
    
    public void onClick(View v){
    	switch(v.getId()){
    		case R.id.btn_writeHaiku:
    			this.btn_writehaiku_click();
    			break;
    		case R.id.img_lnkTwitter:
    			this.img_twitter_click();
    			break;
    		case R.id.img_lnkFacebook:
    			this.img_facebook_click();
    			break;
    		case R.id.img_lnkBlogspot:
    			this.img_blogspot_click();
    			break;
    	}
    }
    
    private void btn_writehaiku_click(){
    	startActivity(new Intent(this, Write_Read_Tabhost.class));
    }
    
    private void img_twitter_click(){
    	this.openUrl(getResources().getString(R.string.url_skTwitter));
    }
    
    private void img_facebook_click(){
    	this.openUrl(getResources().getString(R.string.url_skFacebook));
    }
    
    private void img_blogspot_click(){
    	this.openUrl(getResources().getString(R.string.url_skBlogspot));
    }
    
    private void openUrl(String url){
    	Intent i = new Intent(Intent.ACTION_VIEW);
    	i.setData(Uri.parse(url));
    	startActivity(i);
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu){
    	super.onCreateOptionsMenu(menu);
    	MenuInflater inflater = getMenuInflater();
    	inflater.inflate(R.menu.main_menu, menu);
    	return true;
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
    	switch (item.getItemId()) {
    		case R.id.menu_exit:
    			finish();
    			return true;
    		case R.id.menu_about:
    			ShowAboutScreen();
    			return true;
    	}
    	return false;
    }
    
    private void ShowAboutScreen(){
    	startActivity(new Intent(this, About.class));
    }
}